home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / mgplp378.lha / magplip / source / magplip.h < prev    next >
C/C++ Source or Header  |  1996-04-10  |  12KB  |  339 lines

  1. #ifndef __MAGPLIP_H
  2. #define __MAGPLIP_H
  3. /*
  4. ** $VER: magplip.h 1.14 (10 Apr 1996)
  5. **
  6. ** magplip.device - Parallel Line Internet Protocol
  7. **
  8. ** Original code written by Oliver Wagner and Michael Balzer.
  9. **
  10. ** This version has been completely reworked by Marius Gröger,
  11. ** introducing slight protocol changes. The new source is
  12. ** a lot better organized and maintainable.
  13. **
  14. ** Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ** The new source is significantly faster and yet better maintainable.
  16. **
  17. ** (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ** (C) Copyright 1995 Jan Kratochvil & Martin Mares
  19. ** (C) Copyright 1995 Marius Gröger
  20. **     All Rights Reserved
  21. **
  22. ** $HISTORY:
  23. **
  24. ** 10 Apr 1996 : 001.014 :  + PLIPF_REPLYSS didn't fit into byte
  25. **                          + pb_ExtFlags
  26. ** 09 Apr 1996 : 001.013 :  added TrackRe.tr_Count
  27. ** 29 Mar 1996 : 001.012 :  changed copyright note
  28. ** 30 Dec 1995 : 001.011 :  + single dynamic frame buffer
  29. **                          + added a lot of min/max constants
  30. ** 29 Dec 1995 : 001.010 :  + pb_Startup
  31. **                          + new flag PLIPF_REPLYSS
  32. ** 03 Sep 1995 : 001.009 :  + removed PLIP(F|B)_SIDEA
  33. **                          + hardware addressing fields in PLIPBase
  34. ** 30 Aug 1995 : 001.008 :  support for timer-timed timeout :-)
  35. **                          some pecularities moved to compiler.h
  36. ** 13 Aug 1995 : 001.007 :  code cleanup
  37. ** 29 Jul 1995 : 001.006 :  support for arbitration delay
  38. ** 24 Jul 1995 : 001.005 :  only one delay value in config
  39. **                          some volatile elements in GD
  40. ** 25 Apr 1995 : 001.004 :  #define's FAR
  41. ** 06 Mar 1995 : 001.003 :  added collision delays
  42. ** 04 Mar 1995 : 001.002 :  packet-type now ULONG
  43. ** 18 Feb 1995 : 001.001 :  some SAS/C wrappers, better data base handling
  44. ** 12 Feb 1995 : 001.000 :  reworked original
  45. */
  46.  
  47.    /* system header files */
  48. #ifndef DEVICES_SANA2_H
  49. #include <devices/sana2.h>
  50. #endif
  51. #ifndef EXEC_SEMAPHORES_H
  52. #include <exec/semaphores.h>
  53. #endif
  54. #ifndef EXEC_LISTS_H
  55. #include <exec/lists.h>
  56. #endif
  57. #ifndef EXEC_INTERRUPTS_H
  58. #include <exec/interrupts.h>
  59. #endif
  60. #ifndef EXEC_LIBRARIES_H
  61. #include <exec/libraries.h>
  62. #endif
  63. #ifndef DOS_DOS_H
  64. #include <dos/dos.h>
  65. #endif
  66.  
  67. #ifndef __COMPILER_H
  68. #include "compiler.h"
  69. #endif
  70.  
  71.  
  72. /****************************************************************************/
  73.  
  74.  
  75.    /* memory economy is *everything* :-) */
  76. #define SERVERTASKNAME           pb->pb_DevNode.lib_Node.ln_Name
  77.  
  78.       /* default values */
  79. #define PLIP_DEFMTU              1024
  80. #define PLIP_DEFBPS              100000
  81. #define PLIP_DEFRETRIES          32
  82. #define PLIP_DEFTIMEOUT          (500*1000)
  83. #define PLIP_DEFDELAY            0
  84. #define PLIP_DELAYDIFF           2000
  85. #define PLIP_DEFARBITRATIONDELAY 500
  86.  
  87.       /* minimum values */
  88. #define PLIP_MINPRIORITY         -128
  89. #define PLIP_MINMTU              256
  90. #define PLIP_MINRETRIES          1
  91. #define PLIP_MINCOLLISIONDELAY   0
  92. #define PLIP_MINARBITRATIONDELAY 0
  93. #define PLIP_MINTIMEOUT          500
  94. #define PLIP_MINBPS              1
  95.  
  96.       /* maximum values */
  97. #define PLIP_MAXMTU              (128 * 1024)
  98. #define PLIP_MAXRETRIES          127   /* don't try higher values! */
  99. #define PLIP_MAXPRIORITY         127
  100. #define PLIP_MAXCOLLISIONDELAY   999999
  101. #define PLIP_MAXARBITRATIONDELAY 999999
  102. #define PLIP_MAXTIMEOUT          999999
  103. #define PLIP_MAXBPS              0x7fffffff
  104.  
  105.    /* magPLIPs hardware address: log2(two systems) = 1 */
  106. #define PLIP_ADDRFIELDSIZE       1
  107.  
  108.  
  109. /****************************************************************************/
  110.  
  111.  
  112.    /* this _is_ awful, I know */
  113. #define PKTFRAMESIZE_1           4        /* the sync-field and packet-size */
  114. #define PKTFRAMESIZE_2           6                   /* crc and packet type */
  115.  
  116. struct PLIPFrame {
  117.    USHORT   pf_Sync;
  118.    SHORT    pf_Size;
  119.    USHORT   pf_CRC;
  120.    ULONG    pf_Type;
  121.    /*UBYTE    pf_Data[MTU];*/
  122. };
  123.  
  124.  
  125. #define SYNCBYTE_HEAD   0x42
  126. #define SYNCBYTE_CRC    0x01
  127. #define SYNCBYTE_NOCRC  0x02
  128. #define SYNCWORD_CRC    ((SYNCBYTE_HEAD << 8) | SYNCBYTE_CRC)
  129. #define SYNCWORD_NOCRC  ((SYNCBYTE_HEAD << 8) | SYNCBYTE_NOCRC)
  130.  
  131.  
  132. /****************************************************************************/
  133.  
  134.  
  135. struct TrackRec {
  136.    struct MinNode              tr_Link;
  137.    ULONG                       tr_PacketType;
  138.    ULONG                       tr_Count;
  139.    struct Sana2PacketTypeStats tr_Sana2PacketTypeStats;
  140. };
  141.  
  142.  
  143. /****************************************************************************/
  144.  
  145.  
  146. typedef BOOL (* ASM BMFunc)(REG(a0) void *, REG(a1) void *, REG(d0) LONG);
  147.  
  148. struct BufferManagement
  149. {
  150.     struct MinNode   bm_Node;
  151.     BMFunc           bm_CopyFromBuffer;
  152.     BMFunc           bm_CopyToBuffer;
  153. };
  154.  
  155.  
  156. /****************************************************************************/
  157.  
  158.  
  159.    /*
  160.    ** sent to the server task after being CreateNewProc()ed
  161.    */
  162. struct ServerStartup
  163. {
  164.    struct Message    ss_Msg;
  165.    struct PLIPBase  *ss_PLIPBase;
  166.    BOOL              ss_Error;
  167.    UBYTE             ss_Pad[2];
  168. };
  169.  
  170.  
  171.  
  172. /****************************************************************************/
  173.  
  174.  
  175. enum { S2SS_TXERRORS, S2SS_COLLISIONS, S2SS_COUNT };
  176.  
  177.  
  178.    /*
  179.    ** This count will record the number of packets that failed
  180.    ** to be transmitted.
  181.    */
  182. #define S2SS_PLIP_TXERRORS ((((S2WireType_PLIP) & 0xffff) << 16) | (S2SS_TXERRORS))
  183.  
  184.    /*
  185.    ** This count will record the number of line arbitration collisions
  186.    */
  187. #define S2SS_PLIP_COLLISIONS ((((S2WireType_PLIP) & 0xffff) << 16) | (S2SS_COLLISIONS))
  188.  
  189.  
  190. /****************************************************************************/
  191.  
  192.  
  193. struct PLIPBase
  194. {
  195.    struct Library              pb_DevNode;        /* basic device structure */
  196.    UBYTE                       pb_Unit;         /* unit of 1st OpenDevice() */
  197.    UBYTE                       pb_pad1; /* make the following long alligned */
  198.    BPTR                        pb_SegList;               /* pointer to code */
  199.    struct Library          *   pb_MiscBase,          /* various libs & res. */
  200.                            *   pb_CIAABase,
  201.                            *   pb_UtilityBase,
  202.                            *   pb_TimerBase,
  203.                            *   pb_DOSBase,
  204.                            *   pb_SysBase;
  205.    struct ServerStartup    *   pb_Startup;            /* main server proces */
  206.    struct Process          *   pb_Server;             /* main server proces */
  207.    struct Task             *   pb_Task;         /* used for server shutdown */
  208.    struct Interrupt            pb_Interrupt;          /* for AddICRVector() */
  209.    ULONG                       pb_IntSig;        /* sent from int to server */
  210.    ULONG                       pb_IntSigMask;                  /* for speed */
  211.    ULONG                       pb_ServerStoppedSigMask;     /* for shutdown */
  212.    struct MsgPort          *   pb_ServerPort,       /* for IOReq forwarding */
  213.                            *   pb_TimeoutPort,      /* for timeout handling */
  214.                            *   pb_CollPort;       /* for collision handling */
  215.    struct timerequest          pb_TimeoutReq,       /* for timeout handling */
  216.                                pb_CollReq;        /* for collision handling */
  217.    struct Sana2DeviceStats     pb_DevStats;            /* SANA-2 wants this */
  218.    struct Sana2SpecialStatRecord
  219.                                pb_SpecialStats[S2SS_COUNT];
  220.    volatile struct List        pb_ReadList,                  /* the readers */
  221.                                pb_WriteList,                 /* the writers */
  222.                                pb_EventList,              /* event tracking */
  223.                                pb_ReadOrphanList,   /* for spurious packets */
  224.                                pb_TrackList,                  /* track type */
  225.                                pb_BufferManagement;          /* Copy-In/Out */
  226.    struct SignalSemaphore      pb_EventListSem,     /* protection for lists */
  227.                                pb_ReadListSem,
  228.                                pb_WriteListSem,
  229.                                pb_TrackListSem,
  230.                                pb_ReadOrphanListSem,
  231.                                pb_Lock;
  232.    ULONG                       pb_Retries;                 /* config values */
  233.    ULONG                       pb_ReportBPS;
  234.    ULONG                       pb_MTU;
  235.    ULONG                       pb_AllocFlags;
  236.    ULONG                       pb_Timeout;
  237.    LONG                        pb_CollisionDelay;
  238.    LONG                        pb_ArbitrationDelay;
  239.    volatile UBYTE              pb_TimeoutSet;/* if != 0, a timeout occurred */
  240.    volatile UBYTE              pb_Flags;                       /* see below */
  241.    volatile UWORD              pb_ExtFlags;                    /* see below */
  242.    APTR                        pb_OldExceptCode;
  243.    APTR                        pb_OldExceptData;
  244.    ULONG                       pb_OldExcept;
  245.    UBYTE                       pb_HandshakeMask[2],   /* crossed for side-a */
  246.                                pb_HandshakeBit[2];            /* and side-b */
  247.    UBYTE                       pb_SrcAddr[PLIP_ADDRFIELDSIZE];
  248.    UBYTE                       pb_DstAddr[PLIP_ADDRFIELDSIZE];
  249.    struct PLIPFrame        *   pb_Frame;
  250. };
  251.  
  252.    /*
  253.    ** used as index for PLIPBase->pb_HandshakeMask[]/pb_HandshakeBit[]
  254.    */
  255. #define HS_LINE        0   /* as we use compatible plip wireing, our magic */
  256. #define HS_REQUEST     1   /* is to cross the lines transparently by software */
  257.  
  258. #ifdef __SASC
  259.      /*
  260.      ** redirect all shared library bases to our device base.
  261.      */
  262. #  define SysBase      pb->pb_SysBase
  263. #  define DOSBase      pb->pb_DOSBase
  264. #  define TimeBase     pb->pb_TimeBase
  265. #  define UtilityBase  pb->pb_UtilityBase
  266. #  define MiscBase     pb->pb_MiscBase
  267. #  define CIAABase     pb->pb_CIAABase
  268. #  define CiaBase      pb->pb_CIAABase
  269. #  define TimerBase    pb->pb_TimerBase
  270.      /*
  271.      ** This macro declares a local variable which temporary gets
  272.      ** SysBase directly from AbsExecBase.
  273.      */
  274. #  define LOCALSYSBASE struct { void *pb_SysBase; } *pb = (void*)0x4
  275.      /*
  276.      ** Use this macro as argument for all functions which need to
  277.      ** have access to your data base.
  278.      */
  279. #  define BASEPTR      struct PLIPBase *pb
  280. #else
  281. #  error Please define library bases for your compiler
  282. #endif
  283.  
  284.    /*
  285.    ** Values for PLIPBase->pb_Flags
  286.    ** Note that the Flags field is intentionally only 8 bits wide so that
  287.    ** the ASM parts my use the bit functions.
  288.    */
  289. #define PLIPB_REPLYSS         0   /* server-startup must be replied */
  290. #define PLIPB_EXCLUSIVE       1   /* current opener is exclusive */
  291. #define PLIPB_NOTCONFIGURED   2   /* not configured */
  292. #define PLIPB_OFFLINE         3   /* currently not online (sic!) */
  293. #define PLIPB_SENDCRC         4   /* send with CRC sum */
  294. #define PLIPB_RECEIVING       5   /* set by interrupt */
  295. #define PLIPB_COLLISION       6   /* arbitration detected a collision */
  296. #define PLIPB_SERVERSTOPPED   7   /* set by server while passing away */
  297.  
  298. #define PLIPF_EXCLUSIVE       (1<<PLIPB_EXCLUSIVE)
  299. #define PLIPF_NOTCONFIGURED   (1<<PLIPB_NOTCONFIGURED)
  300. #define PLIPF_OFFLINE         (1<<PLIPB_OFFLINE)
  301. #define PLIPF_SENDCRC         (1<<PLIPB_SENDCRC)
  302. #define PLIPF_RECEIVING       (1<<PLIPB_RECEIVING)
  303. #define PLIPF_COLLISION       (1<<PLIPB_COLLISION)
  304. #define PLIPF_SERVERSTOPPED   (1<<PLIPB_SERVERSTOPPED)
  305. #define PLIPF_REPLYSS         (1<<PLIPB_REPLYSS)
  306.  
  307.    /*
  308.    ** Values for PLIPBase->pb_ExtFlags
  309.    */
  310. #define PLIPEB_NOSPECIALSTATS 0   /* don't report special stats */
  311.  
  312. #define PLIPEF_NOSPECIALSTATS (1<<PLIPEB_NOSPECIALSTATS)
  313.  
  314.  
  315. /****************************************************************************/
  316.  
  317.  
  318.    /*
  319.    ** configuration stuff
  320.    */
  321. #define CONFIGFILE "ENV:SANA2/magPLIP.config"
  322.  
  323. #define TEMPLATE "TIMEOUT/K/N,PRIORITY=PRI/K/N,MTU/K/N,BPS/K/N,RETRIES/K/N,SENDCRC/S,CD=COLLISIONDELAY/K/N,AD=ARBITRATIONDELAY/K/N,NOSPECIALSTATS/S"
  324.  
  325. struct PLIPConfig
  326. {
  327.       ULONG *timeout;
  328.       LONG  *priority;
  329.       LONG  *mtu;
  330.       LONG  *bps;
  331.       LONG  *retries;
  332.       ULONG  sendcrc;
  333.       LONG  *collisiondelay;
  334.       LONG  *arbitrationdelay;
  335.       ULONG  nospecialstats;
  336. };
  337.  
  338. #endif
  339.